<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Google Maps AJAX + mySQL/PHP Example</title>
    <script src="http://maps.google.com/maps/api/js?sensor=false"
            type="text/javascript"></script>
    <script type="text/javascript">
    //<![CDATA[

    var customIcons = {
      restaurant: {
        icon: 'http://labs.google.com/ridefinder/images/mm_20_blue.png',
        shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
      },
      bar: {
        icon: 'http://labs.google.com/ridefinder/images/mm_20_red.png',
        shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
      }
    };

    function load() {
      var map = new google.maps.Map(document.getElementById("map"), {
        center: new google.maps.LatLng(26.927799, -82.055199),
        zoom: 20,
		tilt: 0,
		mapTypeId: google.maps.MapTypeId.SATELLITE,
      });
      var infoWindow = new google.maps.InfoWindow;

      // Change this depending on the name of your PHP file
      downloadUrl("phpsqlajax_genxml1.php", function(data) {
        var xml = data.responseXML;
        var markers = xml.documentElement.getElementsByTagName("marker");
        for (var i = 0; i < markers.length; i++) {
          var name = markers[i].getAttribute("name");
          var address = markers[i].getAttribute("address");
          var type = markers[i].getAttribute("type");
          var point = new google.maps.LatLng(
              parseFloat(markers[i].getAttribute("lat")),
              parseFloat(markers[i].getAttribute("lng")));
          //var html = "<b>" + name + "</b> <br/>" + address;
		  var html = "<b>POST ID</b>:&nbsp;"+name+"<br/><b>LATITUDE</b>:&nbsp;"+markers[i].getAttribute("lat")+"<br/><b>LONGITUDE:&nbsp;</b>"+markers[i].getAttribute("lng")+"<br/><a href=\"signPostManager.php?id="+name+"&action=edit\">CLICK HERE TO EDIT</a>";
          var icon = customIcons['bar'] || {};
          var marker = new google.maps.Marker({
            map: map,
            position: point,
            icon: icon.icon,
            shadow: icon.shadow,
			draggable:true
          });
          bindInfoWindow(marker, map, infoWindow, html);
		  google.maps.event.addListener(marker,'drag',function(event) {
					//document.getElementById('lat').value = this.position.lat();
					//document.getElementById('lng').value = this.position.lng();
					 var info = new google.maps.InfoWindow();
					 info.setContent("ADD NEW POST IN THIS POSIION<br/>LATITUDE:&nbsp;"+this.position.lat()+"<br/>LOGITITUDE:&nbsp;"+this.position.lng());
					 info.open(map,this);
                    //On click the map will load the info window
                    //info.open(map,this);
                    //infos[0]=info;
					 
   					 //info.open(map,marker);
					//alert('Drag end');
					
				});
				
				google.maps.event.addListener(marker,'dragend',function() {
				//document.getElementById('lat').value = this.position.lat();
				//document.getElementById('lng').value = this.position.lng();
				//alert(this.position.lng());
				
				window.location.href = 'signPostManager.php?lng='+this.position.lng()+'&lat='+this.position.lat()+'&action=add';
				//window.open('signPostManager.php?lng='+this.position.lng()+'&lat='+this.position.lat()+'&action=add');
			});
				
        }
      });
    }

    function bindInfoWindow(marker, map, infoWindow, html) {
      google.maps.event.addListener(marker, 'click', function() {
        infoWindow.setContent(html);
        infoWindow.open(map, marker);
      });
    }

    function downloadUrl(url, callback) {
      var request = window.ActiveXObject ?
          new ActiveXObject('Microsoft.XMLHTTP') :
          new XMLHttpRequest;

      request.onreadystatechange = function() {
        if (request.readyState == 4) {
          request.onreadystatechange = doNothing;
          callback(request, request.status);
        }
      };

      request.open('GET', url, true);
      request.send(null);
    }

    function doNothing() {}

    //]]>
  </script>
  </head>

  <body onLoad="load()">
    <div id="map" style="width: 850px; height: 550px"></div>
  </body>
</html>